/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package struts;

import java.util.*;
import javabeans.*;
import Service.*;

/**
 *
 * @author zhi
 */
public class GroupPlanInfo {
    int groupplanid;
    String groupplanname;
    String groupplandescript;
    List<EventInfo> eventInfos;
    List<Member> members;

    public List<Member> getMembers() {
        return members;
    }

    public void setMembers(List<Member> members) {
        this.members = members;
    }

    public List<EventInfo> getEventInfos() {
        return eventInfos;
    }

    public void setEventInfos(List<EventInfo> eventInfos) {
        this.eventInfos = eventInfos;
    }

    public String getGroupplandescript() {
        return groupplandescript;
    }

    public void setGroupplandescript(String groupplandescript) {
        this.groupplandescript = groupplandescript;
    }

    public int getGroupplanid() {
        return groupplanid;
    }

    public void setGroupplanid(int groupplanid) {
        this.groupplanid = groupplanid;
    }

    public String getGroupplanname() {
        return groupplanname;
    }

    public void setGroupplanname(String groupplanname) {
        this.groupplanname = groupplanname;
    }

    public void saveThisGroupPlan() {
        GroupPlanService gps = new GroupPlanServiceImpl();
System.out.println(groupplanid);
        GroupPlan thisplan = gps.getGroupPlan(groupplanid);
        if(thisplan == null) {
            System.out.println("null!");
        }
        //thisplan.setPlanid(id);
        thisplan.setGroupplanname(groupplanname);
        thisplan.setPlandescript(groupplandescript);

        for(int i=0;i<eventInfos.size();i++) {
            EventInfo ei = eventInfos.get(i);
            String operation = ei.getOperation();
            if("new".equals(operation)){
                Event e = ei.getEvent();
System.out.println("new event: "+e.getId());
                gps.addGroupEvent(e.getEventname(), e.getType(), e.getEventdate(), e.getEventtime(), e.getEventdescript(), e.getPointX(), e.getPointY(), e.getColor(), thisplan);
            } else if("modify".equals(operation)) {
                Event e = ei.getEvent();
System.out.println("modify event: "+e.getId());
                gps.modifyGroupEvent(e.getId(), e.getEventname(), e.getType(), e.getEventdate(), e.getEventtime(), e.getEventdescript(), e.getPointX(), e.getPointY(), e.getColor(), thisplan);
            } else if("delete".equals(operation)) {
                Event e = ei.getEvent();
System.out.println("delete event: "+e.getId() + "planid: " + thisplan.getGroupplanid());
                boolean s = gps.deleteGroupEvent(e.getId(), thisplan.getGroupplanid());
System.out.println("delete event: "+s);
            }

        }
    }
}
